package com.icbc.api;

import com.icbc.api.request.QrcodeQueryRequestV2;
import com.icbc.api.request.QrcodeQueryRequestV2.QrcodeQueryRequestV2Biz;
import com.icbc.api.response.QrcodeQueryResponseV2;

/**
 * 工银二维码查询接口
 * 请商户配置SDK中的lib文件夹中的jar包后，根据备注1-6提示进行数据替换
 */
public class QrcodeQueryTest {
	
    
	public static void main(String[] args) throws Exception {
		//签名类型为RSA2
		DefaultIcbcClient client = new DefaultIcbcClient(QrcodeConstants.APP_ID, IcbcConstants.SIGN_TYPE_RSA2, QrcodeConstants.MY_PRIVATE_KEY, QrcodeConstants.APIGW_PUBLIC_KEY);
		QrcodeQueryRequestV2 request = new QrcodeQueryRequestV2();
	
		//4、替换成实联测试环境
		request.setServiceUrl(QrcodeConstants.QRCODE_QUERY_URL);
		
		//5、请对照接口文档用bizContent.setxxx()方法对业务上送数据进行赋值
		QrcodeQueryRequestV2Biz bizContent = new QrcodeQueryRequestV2Biz();
		bizContent.setMerId(QrcodeConstants.MER_ID);//商户号
		bizContent.setCustId("Ey0LsS39FwdE35TsSW1A2eeoIRMZrjSa");//该字段非必输项
		bizContent.setOutTradeNo("ZHL777O15002039");//该字段非必输项,out_trade_no和order_id选一项上送即可
		bizContent.setOrderId("020002040095201802202148776");//该字段非必输项,out_trade_no和order_id选一项上送即可
		request.setBizContent(bizContent);
		
		QrcodeQueryResponseV2 response;
		try {
			response = client.execute(request, "1212SDFSDF");//msgId消息通讯唯一编号，要求每次调用独立生成，APP级唯一
			if (response.isSuccess()) {
			    // 成功
                System.out.println("====调用成功=====");
				//6、业务成功处理，请根据接口文档用response.getxxx()获取同步返回的业务数据
				System.out.println("ReturnCode:"+response.getReturnCode());
				System.out.println("ReturnMsg:" + response.getReturnMsg());
				System.out.println("OutTradeNo:" +response.getOutTradeNo());
				System.out.println("TotalAmt:" +response.getTotalAmt());
			} else {
				//失败
			    System.out.println("====调用失败=====");
				System.out.println("ReturnCode:"+response.getReturnCode());
				System.out.println("ReturnMsg:"+response.getReturnMsg());
			}		
		} catch (IcbcApiException e) {
			e.printStackTrace();
		}
	}	
}